package com.xuecheng.content.api.controller;

import com.xuecheng.base.exception.ValidationGroups;
import com.xuecheng.base.model.PageParam;
import com.xuecheng.base.model.PageResult;
import com.xuecheng.content.model.dto.AddCourseDto;
import com.xuecheng.content.model.dto.CourseBaseInfoDto;
import com.xuecheng.content.model.dto.EditCourseDto;
import com.xuecheng.content.model.dto.QueryCourseParamDto;
import com.xuecheng.content.model.po.CourseBase;
import com.xuecheng.content.services.service.CourseBaseInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Author:王亚栋
 * @Date: 2023/7/6 下午8:51
 * @Version:1.0
 */
@RestController
@Api(value = "课程信息管理接口",tags = "课程信息管理接口")
public class CourseBaseInfoController {

    @Autowired
    private CourseBaseInfoService courseBaseInfoService;
    /**
     *
     * @param pageParam 分页参数
     * @param queryCourseParamDto  通过json数据传入
     * @return
     */
    @ApiOperation("课程查询接口")
    @PostMapping("/course/list")
    public PageResult<CourseBase> list(PageParam pageParam,
                                       @RequestBody(required = false) QueryCourseParamDto queryCourseParamDto){


        return courseBaseInfoService.queryCourseBaseList(pageParam,queryCourseParamDto);
    }

    /**
     * 新增课程功能
     * @param addCourseDto
     * @return
     */
    @ApiOperation("新增课程")
    @PostMapping("/course")
    public CourseBaseInfoDto createCourseBase(@RequestBody @Validated(ValidationGroups.Insert.class) AddCourseDto addCourseDto){

        //获取到用户所属机构的ID
        Long companyId = 1232141425L;

        return courseBaseInfoService.createCourseBase(companyId,addCourseDto);
    }

    @ApiOperation("通过ID查询课程")
    @GetMapping("/course/{id}")
    public CourseBaseInfoDto getCourseBaseById(@PathVariable("id") Long courseId){

       return courseBaseInfoService.getCourseBaseInfo(courseId);

    }

    @ApiOperation("修改课程基础信息")
    @PutMapping("/course")
    public CourseBaseInfoDto modifyCourseBase(@RequestBody @Validated EditCourseDto editCourseDto){

        //获取到用户所属机构的ID
        Long companyId = 1232141425L;

        return courseBaseInfoService.updateCourseBase(companyId, editCourseDto);


    }
}
